# coding=utf-8

import os
from openpyxl import load_workbook

target_dirpath = r"I:\test0819-12"
target_filename = '1.xlsx'


def xlsx_R():
     
    workbook1 = load_workbook(target_dirpath + "\\" + target_filename)
    # booksheet = workbook.active                #获取当前活跃的sheet,默认是第一个sheet
    sheets1 = workbook1.get_sheet_names()  # 从名称获取sheet
    booksheet = workbook1.get_sheet_by_name(sheets1[0])
     
    rows = booksheet.rows
    for row in rows:
        cell_ = row[1]
        if cell_.hyperlink:
            print("%s\t%s" % (cell_.value, cell_.hyperlink.display))
        else:
            print("%s\tNone" % (cell_.value))
#     columns = booksheet.columns
#     nrows, ncols = len(rows), len(columns)
#     print("nrows=%s, ncols=%s" % (nrows, ncols))
    
    # 迭代所有的行
#     for r in range(1,4):
#         for c in range(1,4):
#             cell_ = booksheet.cell(row=r, column=c)
#             print("(%s, %s)=%s\t%s" % (r, c, cell_.value, cell_.hyperlink.display))


def xlsx_W():
#     workbook = xlwt.Workbook(encoding='utf-8')
#     booksheet = workbook.add_sheet('Sheet 1', cell_overwrite_ok=True)
#     
#     #  写单元格
#     booksheet.write(0, 0, 34)
#     # 合并单元格
#     
#     # 写&合并单元格
    return 1


def xlsx_RW():
    return


if __name__ == '__main__':
    
    # 1读xlsx的超链接和文字
    xlsx_R()
    
    # 2写xlsx的超链接和文字
    
    # 3更新xlsx的超链接和文字
    
